package core

import (
	"github.com/hpcloud/tail"
	"kuafu/config"
	"kuafu/progress/log"
)

type Watcher struct {
	tailCh *tail.Tail
}

func (watcher *Watcher) Watch(config *config.AppConfig) {

	seekInfo := &tail.SeekInfo{
		Offset: config.OffSet.OffsetLine,
		Whence: config.OffSet.OffsetMod,
	}

	tailFile, err := tail.TailFile(config.LogFile.Path, tail.Config{
		Location:  seekInfo,
		ReOpen:    true,
		MustExist: false,
		Poll:      true,
		Follow:    true,
	})

	if err != nil {
		log.Log.Fatalln(err)
	}

	watcher.tailCh = tailFile

}
